import type { MaybeRef } from 'vue';

export function useGameCascader(type: MaybeRef<string | undefined>) {
  const typeR = toRef(type);
  const gameTypeQry = useQuery({
    queryKey: [apis.apiGameTypeSelect.id],
    queryFn: () => apis.apiGameTypeSelect(undefined),
  });
  const gameTypeOptions = computed(() => gameTypeQry.data.value?.map(item => ({
    value: item.alias,
    label: item.name,
    children: item.game?.map(item => ({ value: item.code, label: item.name })),
  })));
  const gameOptions = computed(() => gameTypeOptions.value?.find(x => x.value === typeR.value)?.children);

  return { gameTypeOptions, gameOptions };
}
